let express = require("express");
let api = express.Router();
let cryptor = require("../classes/crypto.js");

// let cryptoManager = new cryptor();

//获取公钥
api.get("/key", function( req , res , next ){

    let key = cryptor().getPublicKey();

    res.statusCode = 200;
    res.send(JSON.stringify({
        code: 0,
        data:{
            key : key
        }
    }));
    res.end();
});

//错误处理
api.use(function( err , req , res , next){
    console.log("err: ", err);
    if( err ){

        res.statusCode= err.status;
        res.send( JSON.stringify({
            code: err.code,
            msg: err.msg
        }) );
        res.end();
    }else{
        next();
    }
    
});



module.exports = api;